const { join } = require('path')

const Client = require('../tables/Client')
const MappingPort = require('../tables/MappingPort')
const os = require('os')
const _ = require('lodash')

module.exports = {
    clients: new Client(),
    connections: new Map(),
    tree: new Map(),
    views: {},
    dispatchViewsEvent(contentId, name, data) {
        _.forOwn(this.views, view => {
            if (view.contentId == contentId) {
                view.onFn(name, data)
            }
        })
    },
    mappedPortTable: new MappingPort(),
    mappingPorts: new Map(),
    shell: {},
    constant: {
        viewPath: '',
        utilPath: '',
        rootPath: '',
        sshPath: '',
        cachePath: '',
        context: null,
        setContext(ctx) {
            this.context = ctx
            this.rootPath = ctx.extensionPath
            this.viewPath = join(this.rootPath, 'src', 'views')
            this.utilPath = join(this.rootPath, 'src', 'utils')
            this.cachePath = join(os.homedir(), '.fubowen-server-manager')
            this.sshPath = join(os.homedir(), '.ssh')
        }
    },
    viewsContainers: {
        left: {
            id: 'leftContainer',
            views: {
                default: {
                    id: 'extensions.leftView'
                }
            }
        },
        right: {
            id: 'rightContainer',
            views: {
                default: {
                    id: 'extensions.rightView'
                }
            }
        }
    },
    ViewTypeEnum: {
        DIALOG: 'DIALOG',
        VIEW: 'VIEW'
    },
    version: '1.0',
    disposables: []
}
